package com.devmindset.legoframework.usage.client.screen;

import com.devmindset.legoframework.client.layout.LegoScreenLayout;
import com.devmindset.legoframework.client.mvc.metadata.PlaceholderMapping;
import com.devmindset.legoframework.client.mvc.metadata.ScreenStory;
import com.devmindset.legoframework.client.mvc.metadata.Stories;
import com.devmindset.legoframework.client.screen.ApplicationScreen;
import com.devmindset.legoframework.client.screen.LegoPlaceholder;
import com.devmindset.legoframework.usage.client.component.BannerComponent;
import com.devmindset.legoframework.usage.client.component.CalendarComponent;
import com.devmindset.legoframework.usage.client.component.CountryDetailsComponent;
import com.devmindset.legoframework.usage.client.component.FooterComponent;
import com.devmindset.legoframework.usage.client.component.HeaderComponent;
import com.devmindset.legoframework.usage.client.component.NavigationComponent;
import com.devmindset.legoframework.usage.client.component.OverviewComponent;
import com.devmindset.legoframework.usage.client.component.PendingOrdersComponent;
import com.devmindset.legoframework.usage.client.text.UsageTexts;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.Layout;
import com.smartgwt.client.widgets.layout.VLayout;

public class MainScreen extends ApplicationScreen {

	private LegoScreenLayout screenLayout;
	
	private LegoPlaceholder header;
	private LegoPlaceholder footer;
	private LegoPlaceholder navigation;
	private LegoPlaceholder banners;
	private LegoPlaceholder calendar;
	private LegoPlaceholder main;
	
	private HLayout mainArea;
	private VLayout leftArea;
	
	/** {@inheritDoc} */
	@Override
	protected Layout drawLayout() {
		screenLayout = new LegoScreenLayout();
		
		header = new LegoPlaceholder();
		header.setHeight(30);
		header.setWidth100();
		
		mainArea = new HLayout();
		mainArea.setWidth100();
		mainArea.setHeight100();
		
		leftArea = new VLayout();
		leftArea.setWidth(300);
		leftArea.setHeight100();
		leftArea.setShowResizeBar(false);
		leftArea.setCanDragResize(false);
		leftArea.setShowEdges(true);
		
		navigation = new LegoPlaceholder();
		navigation.setWidth100();
		navigation.setHeight(167);
				
		calendar = new LegoPlaceholder();
		calendar.setWidth100();
		calendar.setHeight(213);
		
		banners = new LegoPlaceholder();
		banners.setWidth100();
		banners.setHeight100();
		
		leftArea.addMember(navigation);
		leftArea.addMember(calendar);		
		leftArea.addMember(banners);
		
		main = new LegoPlaceholder(true);
		main.setHeight100();
		main.setWidth("*");
		main.setShowEdges(true);
		
		mainArea.addMember(leftArea);
		mainArea.addMember(main);
		
		footer = new LegoPlaceholder();
		footer.setHeight(30);
		footer.setWidth100();
		footer.setShowEdges(true);
		
		screenLayout.addMember(header);
		screenLayout.addMember(mainArea);
		screenLayout.addMember(footer);
		
		return screenLayout;
	}
	
	/** {@inheritDoc} */
	@SuppressWarnings("unchecked")
	public ScreenStory myStory() {
		return Stories.screen()
			.consistsOf(
					new HeaderComponent(),
					new FooterComponent(),
					new NavigationComponent(),
					new OverviewComponent(),
					new PendingOrdersComponent(),
					new CountryDetailsComponent(),
					new BannerComponent(),
					new CalendarComponent()
			)
			.initialState(
					new HeaderComponent(),
					new FooterComponent(),
					new NavigationComponent(),
					new OverviewComponent(),
					new BannerComponent(),
					new CalendarComponent()
			)
			.placeholderMappings(
					new PlaceholderMapping(header, HeaderComponent.class),
					new PlaceholderMapping(footer, FooterComponent.class),
					new PlaceholderMapping(navigation, NavigationComponent.class),
					new PlaceholderMapping(banners, BannerComponent.class),
					new PlaceholderMapping(calendar, CalendarComponent.class),
					new PlaceholderMapping(
							main, 
							OverviewComponent.class, PendingOrdersComponent.class,
							CountryDetailsComponent.class
					)
			)
			.knownAs("Main Application Screen");
	}
	
	/** {@inheritDoc} */
	protected String loadingMessage() {
		return UsageTexts.get().loadingMainScreen();
	}

}